package com.geekteam.manga.Utils;

import java.lang.reflect.Type;
import java.util.List;

import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;

public class JsonUtils {
	
	public static String toJson(Object obj) {
		return new Gson().toJson(obj);
	}
	
	public static Object fromJson(String json, Class<?> X) {
		Object result = null;
		try{
			result = new Gson().fromJson(json, X);
		}catch(JsonSyntaxException ex){
			return null;
		}
		return result;
	}
	
	public static List<?> fromArrayJson(String json, Class<?> X){
		Type type = new TypeToken<List<Object>>(){}.getType();
		return new Gson().fromJson(json, type);
	}
}
